
String.prototype.replaceAll = function(s1, s2) {        
    var temp = this;        
    while (temp.indexOf(s1) != -1) {        
        temp = temp.replace(s1, s2);        
    }        
    return temp;        
}

Array.prototype.max = function(){   
return Math.max.apply({},this)  
}  
Array.prototype.min = function(){   
return Math.min.apply({},this)  
}
function getQueryString(name)
{
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r!=null)return  unescape(r[2]); return null;
}

function query(name,parameter){
	var paramOrder=[];
	if(parameter!=null){
	$.each(parameter, function(i) {
	 if(i!="RN"){
	    	var datav = parameter[i]
			paramOrder.push(i);
			if(typeof datav=="object"){
	    	parameter[i]=JSON.stringify(datav);
			}
	    }
	})
	parameter["paramOrder"]=paramOrder.join(",");
	}
	var results;
	$.ajax({
            url: "/suite/plugins/servlet/query/"+name,
			   type:"post",
			   data:parameter,
			   async:false,
		           success: function (text) {
					   if(text.indexOf("{")==0){
					   text="["+text+"]"
					   results = eval(text)
					   }else{
					   results = eval(text)
					   }
		            },
		            error: function () {
				alert(name+":出错了")
		           }
	  });
	  return results;
}

function execute(name,parameter){
	var paramOrder=[];
	if(parameter!=null){
		$.each(parameter, function(i) {
		 if(i!="RN"){
				var datav = parameter[i]
				paramOrder.push(i);
				if(typeof datav=="object"){
					parameter[i]=JSON.stringify(datav);
				}
			}
		})
		parameter["paramOrder"]=paramOrder.join(",");
	}
	var results;
	$.ajax({
            url: "/suite/plugins/servlet/execute/"+name,
			   type:"post",
			   data:parameter,
			   async:false,
		           success: function (text) {
		            	results=text;
		            },
		            error: function () {
						alert(name+":出错了")
		           }
	  });
	  return results;
}

function uploadFile(thiss,cllback){
		$("body").append("<iframe id='uploadFile' name='ifm' style='display:none;'  ></iframe>");
		
		var file = $(thiss);
		
		var win2 = document.getElementById('uploadFile').contentWindow;
		if(win2.document.body!='undefiend'&&win2.document.body!=null){
				win2.document.body.innerText="";
		}
		var timer;
		var fileinfo = "";
		var form = document.getElementById('uploadForm');
		form.focus();
		form.submit();
		timer = setInterval(dodo,500);
		function dodo(){
			var win = document.getElementById('uploadFile').contentWindow;
			if(win.document.body=='undefiend'||win.document.body==null){
				return;
			}
			var info = win.document.body.innerText;
			fileinfo = info;
			if(fileinfo.length>0){	
				clearInterval(timer);
				$("#uploadFile").remove();
				var rs = eval("["+fileinfo+"]")[0].result.list;
				cllback(rs);
				file.val("");
			}
		}
}

function uploadFileById(thiss,formId,cllback){
		$("body").append("<iframe id='uploadFile' name='ifm'  style='display:none;' ></iframe>");
		
		var file = $(thiss);
		
		var win2 = document.getElementById('uploadFile').contentWindow;
		if(win2.document.body!='undefiend'&&win2.document.body!=null){
				win2.document.body.innerText="";
		}
		var timer;
		var fileinfo = "";
		$("#"+formId+"Form").submit();
		timer = setInterval(dodo,500);
		function dodo(){
			var win = document.getElementById('uploadFile').contentWindow;
			if(win.document.body=='undefiend'||win.document.body==null){
				return;
			}
			var info = win.document.body.innerText;
			fileinfo = info;
			if(fileinfo.length>0){	
				clearInterval(timer);
				$("#uploadFile").remove();
				var rs = eval("["+fileinfo+"]")[0].result.list;
				cllback(rs);
				file.val("");
			}
		}
}

function  time(){
	return new Date().getTime();
}

function requestServlet(servletUrl,parameter,success,failure){
	$.ajax({
		url:'/suite/plugins/servlet/'+servletUrl,
		data:parameter,
		type:'post',
		async: false,
		cache:false,
		success:function(rs) {
			if(rs.code==0){
				success(rs.result);
			}else{
				console.log(rs);
				failure(rs.msg);
			}
		},
		error : function() {
			console.log("background error");
			failure("background error");
		}
	});
}